package com.woniuxy.factory.Interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *拦截器，登陆状态验证
 */

public class LoginInterceptor implements HandlerInterceptor {
    /*请求处理前调用*/
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object account = request.getSession().getAttribute("account");
        System.out.println(account);
        System.out.println(12121);
        if (account == null){
            response.sendRedirect("/page/login-1.html");
//            request.getRequestDispatcher("/page/logln-1.html").forward(request, response);
            return false;
        }

        return true;
    }
    /*请求处理中调用*/
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {


    }
    /*请求处理后调用*/
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
